package com.yanqu.road.server.cmd.player;

import com.yanqu.road.pb.player.HideVipAndAddressProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Author wpj
 * @Date 2020/12/22
 */
@Cmd(code = GameProtocol.S_SET_HIDING_VIP_AND_ADDRESS, desc = "设置隐藏vip跟地址")
public class SettingHideVipAndAddressCmd extends AbstractCommand {

    int hide = 0;
    int type = 0;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        HideVipAndAddressProto.HideVipAndAddressReqMsg msg = HideVipAndAddressProto.HideVipAndAddressReqMsg.parseFrom(packet.getBytes());
        hide = msg.getHide();
        type = msg.getType();
        if (type < 0) {
            return false;
        }
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        int mark = player.getUserInfo().getHideVipAndAddress();
        if (hide == 1) {
            // 隐藏 添加状态
            mark |= (1 << type);

        } else {
            mark = (mark & ~(1 << type));
        }


        player.getUserInfo().setHideVipAndAddress(mark);
        player.getModule(PlayerModule.class).onUserInfoChange();
    }

    @Override
    public void sendData(GamePlayer player) {
        HideVipAndAddressProto.HideVipAndAddressRespMsg.Builder builder = HideVipAndAddressProto.HideVipAndAddressRespMsg.newBuilder();
        builder.setRet(0);
        player.sendPacket(ClientProtocol.U_SET_HIDING_VIP_AND_ADDRESS, builder);
    }
}
